package leetcode.easy;

import leetcode.base.ListNode;

/**
 * ClassName: $206_ReverseList
 * Description:
 * date: 2021/9/13 12:48
 *
 * @author liyifan
 */
public class $206_ReverseList {
    public ListNode reverseList(ListNode head) {
        ListNode prev = null;
        ListNode now = head;

        while (now != null) {
            ListNode temp = now.next;
            now.next = prev;
            prev = now;
            now = temp;
        }
        return prev;
    }

    public ListNode reverseListRecur(ListNode head) {
        if (head == null || head.next == null)
            return head;

        ListNode last = reverseListRecur(head.next);
        head.next.next = head;
        head.next = null;
        return last;
    }

}
